﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Excel = Microsoft.Office.Interop.Excel;

//////////////////////////////////////////////////////////////////////////
//  
namespace excel003
{
    class XPaidAndUnpaidParser
    {
        // Data Member
        private string _filename;
        private int _k_index_worksheet = 1;
        private string _k_keyword_Currency = "Currency";
        private string _k_keyword_Instrument = "Instrument";

        private int _rowNumber;
        private int _columnNumber;

        public int RowNumber
        {
            get
            {
                return _rowNumber;
            }
        }

        public int ColumnNumber
        {
            get
            {
                return _columnNumber;
            }
        }

        // Member Function
        public void excelParser(string in_filename)
        {
            _filename = in_filename;

            //Open Excel File
            Excel.Application excelApp;
            Excel.Workbook excelWorkbook;
            Excel.Worksheet excelWorksheet;
            Excel.Range excelRange;
            /* Reference: MSDN-Microsoft.Office.Interop.Excel.Range
             * Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3-D range.
             */

            excelApp = new Excel.Application();
            excelWorkbook = excelApp.Workbooks.Open(
                    in_filename,    // filename
                    0,              // update links
                    true,           // readonly
                    5,              // format
                    "",             // password
                    "",             // WriteResPassword
                    true,           // IgnoreReadOnlyRecommended
                    Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,  //Origin
                    "\t",           // Delimiter
                    false,          // Editable
                    false,          // Notify
                    0,              // converter
                    true,           // AddToMru
                    1,              // Local
                    0               // CorruptLoad
                );
            excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets.get_Item(_k_index_worksheet);
            excelRange = excelWorksheet.UsedRange;

            _rowNumber = excelRange.Rows.Count;
            _columnNumber = excelRange.Columns.Count;

            string currencyReg = "\bConcurrency";

            excelRange = excelWorksheet.get_Range("A1", "A" + _rowNumber.ToString());
            System.Array column1All = null;
            for (int i = 0; i <= _columnNumber; ++i)  //traversal column1, and find out currency and instrument
            {
                column1All = (System.Array)excelRange.Cells.Value2;
            }

            foreach (object column_data in column1All)
            {
                System.Console.Write("{0} ", column_data);
            }






        }
       
    }
}
